import React, { useState, useEffect } from 'react'
import { Col, Form, Input, Button, Table, message, } from 'antd'
import { PageHeaderWrapper } from '@ant-design/pro-layout'
import RenderButtom from '@/components/RenderButton'
import SearchBox from '@/components/SearchBox'
import {
  fetchTradeList,
} from '@/services/setting/trade'
import { router } from 'umi'

const hasSearchBtn = JSON.parse(localStorage.getItem('hasSearchBtn'))
const columns = [
  {
    title: '门店名称',
    dataIndex: 'storeName',
    key: 'storeName',
  },
  {
    title: '跳转页面',
    dataIndex: 'url',
    key: 'url',
  },
  {
    title: '发货天数',
    dataIndex: 'deliveryTime',
    key: 'deliveryTime',
  },
  {
    title: '库存类型',
    dataIndex: 'lessInventoryType',
    key: 'lessInventoryType',
    render: (t) => <>{t == 1 ? '下单减库存' : t == 2 ? '支付减库存' : null}</>
  },
];
const TradeList = props => {
  const { form } = props
  const { getFieldDecorator } = form
  const [data, setData] = useState([])

  useEffect(() => {
    init()
  }, [])

  const init = async params => {
    const res = await fetchTradeList(params)
    res.code == 0 ? setData(res.data) : message.warning(res.msg)
  }

  // 表单查询
  const handleSearch = e => {
    e.preventDefault()
    form.validateFields((err, values) => {
      console.log('Received values of form: ', values)

    })
  }
  // 表单清空
  const handleReset = e => {
    form.resetFields();
  }
  // 查询条件
  const getFields = () => {
    return(
      <Col span={8}>
        <Form.Item label={`名称`}>
          {getFieldDecorator(`id`, {})
            (<Input />)}
        </Form.Item>
      </Col>
    )
  }
  // 按钮处理
  const handleBtn = type => {
    switch (type) {
      case 12:   
        return router.push('/setting/trade/setting')  
      default:
        break;
    }
  }
  return (
    <PageHeaderWrapper>
      {/* <SearchBox handleReset={handleReset} handleSearch={handleSearch} getFields={getFields} /> */}
      <RenderButtom click={handleBtn} />
      <Table 
        columns={columns}
        // dataSource={data}
        rowKey={r => r.id}
      />
    </PageHeaderWrapper>
    )
}

export default Form.create()(TradeList)
